<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">



            <div class="filter-container">
                <el-date-picker
                        @change="selectByDate"
                        v-model="value.orderDate"
                        type="datetimerange"
                        :picker-options="pickerOptions2"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        align="right">
                </el-date-picker>
                <el-select v-model="value.orderType" placeholder="请选择" @change="selectByOrderType">
                    <el-option
                            v-for="item in options01"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
                <el-select v-model="value.orderStatus" placeholder="请选择" @change="selectByOrderStatus">
                    <el-option
                            v-for="item in options02"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>

                <el-input placeholder="会员姓名/手机号" v-model="value.orderString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="search()" class="dalfBut">查询</el-button>

                <el-button type="primary" class="butT" @click="handleClear()">清除</el-button>
            </div>

            <!--列表数据dataList-->
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="member_name" label="会员姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="电话号码" align="center"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center">
                    <template slot-scope="scope" style="width:42%">
                        <!--<span v-model="scope.row.orderStatus" prop="orderStatus"></span>-->
                        {{scope.row.orderStatus}}
                        <el-switch
                                v-model="scope.row.orderStatus"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                active-value="未到诊"
                                inactive-value="已完成"
                                @change="changeOrderStatus(scope.row)"
                        >
                        </el-switch>
                    </template>
                </el-table-column>

                <el-table-column prop="setmeal_name" label="套餐名称" align="center"></el-table-column>

                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="advice(scope.row)">建议</el-button>
                        <el-button size="mini" type="primary" @click="update(scope.row)">更新</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        background
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <div class="add-form">
                <el-dialog title="健康提醒" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="注意事项">
                                                <el-input v-model="formData.doctorAdvice" type="textarea"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>

                            <el-tab-pane label="运动库" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>运动名称</th>
                                            <th>运动次数</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.sid" v-model="sportIds" type="checkbox" :value="c.sid">
                                            </td>
                                            <td><label :for="c.sid">{{c.name}}</label></td>
                                            <td><label :for="c.sid">{{c.frequency}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>


                            <el-tab-pane label="膳食库" name="third">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>膳食名称</th>
                                            <th>膳食说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="f in foodData">
                                            <td>
                                                <input :id="f.foodId" v-model="foodIds" type="checkbox" :value="f.foodId">
                                            </td>
                                            <td><label :for="f.foodId">{{f.foodName}}</label></td>
                                            <td><label :for="f.foodId">{{f.foodExplain}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>

                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            // value1: true,
            // value2: true,
            // value8: true,
            pickerOptions2: {},
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList:[],//列表数据
            formData:{},//表单数据
            tableData:[],
            foodData:[],
            sportIds:[],
            foodIds:[],
            order_id:[],

            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            options01: [{
                value: '微信预约',
                label: '微信预约'
            }, {
                value: '电话预约',
                label: '电话预约'
            }],
            options02:[{
                value: '未到诊',
                label: '未到诊'
            }, {
                value: '已完成',
                label: '已完成'
            }],
            value:{
                orderDate:'',
                orderType:'',
                orderStatus: '',
                orderString:''
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //按钮改变状态
            changeOrderStatus(row){
                axios.post("/orderController/changeOrderStatus.do?id="+row.id).then((response)=>{
                    if(response.data.flag){
                    }
                })
            },
            //清除按钮
            handleClear(){
                this.pagination.currentPage=1;
                this.value={}
                this.dataList=''
                this.findPage();
            },
            // 根据预约状态查询
            selectByOrderStatus(){
                this.pagination.currentPage=1;
                var param={
                    currentPage:this.pagination.currentPage,    //页码
                    pageSize:this.pagination.pageSize,          //每页显示的记录数
                    queryString:this.value.orderStatus//查询条件
                }
                axios.post("/orderController/findByOrderStatus.do",param).then((response)=>{
                    this.pagination.total=response.data.total;
                    this.dataList=response.data.rows;
                })

            },
            //根据预约类型查询
            selectByOrderType(){
                this.pagination.currentPage=1;
                var param={
                    currentPage:this.pagination.currentPage,    //页码
                    pageSize:this.pagination.pageSize,          //每页显示的记录数
                    queryString:this.value.orderType//查询条件
                }
                axios.post("/orderController/findByOrderType.do",param).then((response)=>{
                    this.pagination.total=response.data.total;
                    this.dataList=response.data.rows;
                })
            },
            //根据日期查询
            selectByDate(){
                this.pagination.currentPage=1;
                var param={
                    currentPage:this.pagination.currentPage,    //页码
                    pageSize:this.pagination.pageSize,          //每页显示的记录数
                    orderDate:this.value.orderDate  //查询条件
                }
                axios.post("/orderController/findByDate.do",param).then((response)=>{
                    this.pagination.total=response.data.total;
                    this.dataList=response.data.rows;
                })
            },
            //处理查询
            search(){
                this.pagination.currentPage=1;
                var param={
                    currentPage:this.pagination.currentPage,    //页码
                    pageSize:this.pagination.pageSize,          //每页显示的记录数
                    queryString:this.value.orderString  //查询条件
                }
                axios.post("/orderController/findByOrderString.do",param).then((response)=>{
                    this.pagination.total=response.data.total;
                    this.dataList=response.data.rows;
                })
            },
            // 编辑
            handleEdit() {
                // console.assert( row.id);
                // window.alert(row.id)
                axios.post("/edit.do?setmealId="+this.setmealIds,this.formData).then((res)=>{
                    if (res.data.flag){
                        //修改成功
                        this.$message({
                            type:'success',
                            message:res.data.message,
                            center:true
                        })
                        // 分页查询
                        this.findPage();
                    }else {
                        //修改失败
                        this.$message({
                            type:'error',
                            message:res.data.message,
                            center:true
                        });
                    }
                }).finally(()=>{
                    //关闭编辑窗口
                    this.dialogFormVisible4Edit=false;
                });
            },
            //添加
            handleAdd () {
                //添加干預表并返回id
                axios.post("/intervention/addIntervention.do?order_id="+this.order_id,this.formData).then((response)=>{
                    if(response.data.flag){
                        this.formData.interventionId = response.data.data;
                        console.log(response.data.data);
                        //添加干預和運動中間表
                        // window.alert(this.foodData.data.foodIds)
                        axios.get("/intervention/addInterventionAndExercise.do?interventionId="+ this.formData.interventionId+"&sportIds="+this.sportIds).then((res)=>{
                            if (res.data.flag){
                                //添加干預和膳食中間表
                                axios.get("/intervention/addInterventionAndFood.do?interventionId="+ this.formData.interventionId+"&foodIds="+this.foodIds).then((response)=>{
                                    if(response.data.flag){
                                        this.$message.success("干预成功！")
                                        this.dialogFormVisible4Edit=false;
                                    }
                                })
                            }
                        })
                    }
                }).finally(()=>{
                    //关闭新增窗口
                    this.dialogFormVisible=false;
                    //分页查询
                    this.findPage();
                })
            },
            //分页查询
            findPage() {
                //分页参数
                var param={
                    currentPage:this.pagination.currentPage,    //页码
                    pageSize:this.pagination.pageSize,          //每页显示的记录数
                    queryString:this.pagination.queryString     //查询条件
                }
                //发送Ajax请求
                axios.post("/orderController/findPage.do",param).then((res)=>{
                    //设置总记录数，分页才能正常显示
                    this.pagination.total=res.data.total;
                    //显示分页数据
                    this.dataList=res.data.rows;
                })
            },
            // 重置表单
            resetForm() {
                this.formData={};
            },
            //健康干预
            advice(row){
                //验证是否到诊
                // window.alert(row.id)
                axios.get("/intervention/verifyOrderStatus.do?id="+row.id).then((response)=>{
                    if(response.data.data){
                        //验证是否进行了健康干预
                        axios.post("/intervention/verifyIntervention.do?id="+row.id).then((response)=>{
                                if(response.data.data){
                                    //验证通过，弹出干预页面并回显数据
                                    this.dialogFormVisible4Edit=true;
                                    this.resetForm();
                                    this.activeName='first';
                                    this.sportIds=[];
                                    this.foodIds=[];
                                    this.formData.order_Id=row.id;
                                    axios.post("/intervention/querySport.do").then((response=>{
                                        if(response.data.flag){
                                            this.tableData=response.data.data
                                        }
                                    }));
                                    //2.查询膳食库数据
                                    axios.post("/intervention/queryFood.do").then((response)=>{
                                        if(response.data.flag){
                                            this.foodData=response.data.data
                                        }
                                    })
                                }else {
                                    this.$message.error("该用户已进行干预！");
                                }
                            }
                        )
                    }else {
                        this.$message.error("该用户还未到诊！");
                    }
                })
            },
            //更新
            update(row){
                //验证是否到诊
                // window.alert(row.id)
                axios.get("/intervention/verifyOrderStatus.do?id="+row.id).then((response)=>{
                    if(response.data.data){
                        //验证是否进行了健康干预
                        axios.post("/intervention/verifyIntervention.do?id="+row.id).then((response)=>{
                                if(!response.data.data){
                                    //验证通过，弹出更新页面并回显数据
                                    this.dialogFormVisible4Edit=true;
                                    this.resetForm();
                                    this.activeName='first';
                                    this.sportIds=[];
                                    this.foodIds=[];
                                    this.order_id=row.id
                                    this.formData.order_Id=row.id;
                                    //回顯醫生建議
                                    axios.post("/intervention/queryAdvice.do?id="+row.id).then((response)=>{
                                        if(response.data.flag){
                                            this.formData.doctorAdvice=response.data.data
                                        }
                                    })
                                    //回显运动库
                                    axios.post("/intervention/querySport.do").then((response=>{
                                        if(response.data.flag){
                                            this.tableData=response.data.data
                                            //查询对应运动库数据
                                            axios.post("/intervention/queryExerciseByIntervention.do?id="+row.id).then((response)=>{
                                                if(response.data.flag){
                                                    this.sportIds= response.data.data
                                                }
                                            })
                                        }
                                    }));
                                    //回显膳食库
                                    axios.post("/intervention/queryFood.do").then((response)=>{
                                        if(response.data.flag){
                                            this.foodData=response.data.data
                                            //查询对应膳食库数据
                                            axios.post("/intervention/queryFoodByIntervention.do?id="+row.id).then((response)=>{
                                                if(response.data.flag){
                                                    this.foodIds= response.data.data
                                                }
                                            })
                                        }
                                    })
                                }else {
                                    this.$message.error("该用户还没有进行干预！");
                                }
                            }
                        )
                    }else {
                        this.$message.error("该用户还未到诊！");
                    }
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //更改模型数据中的当前页
                this.pagination.currentPage = currentPage;
                //分页查询
                this.findPage();
            },
        }
    })
</script>
</html>
